<template>
  <div
      class="container"
      :style="{
        top: y + '%',
        left: x + '%',
        width: '100%',
        height: height + '%',
        opacity: visible ?  1 : 0,
        }"
  >


    <p>{{ this.question == '' ?  ' ' : this.question }}</p>
    <p :class="this.question !== '' ? 'option-border-show' : 'option-border'" class="option-border"></p>

    <!--    选项div-->
    <div class='option-container'>


      <div v-if="choice1.trim() !== ''" class="item-container" @click="onChoose(action1)">
        <span class="text-overlay">{{ choice1 }}</span>
      </div>

      <div v-if="choice2.trim() !== ''" class="item-container" @click="onChoose(action2)">
        <span class="text-overlay">{{ choice2 }}</span>
      </div>

      <div v-if="choice3.trim() !== ''" class="item-container" @click="onChoose(action3)">
        <span class="text-overlay">{{ choice3 }}</span>
      </div>

      <div v-if="choice4.trim() !== ''" class="item-container" @click="onChoose(action4)">
        <span class="text-overlay">{{ choice4 }}</span>
      </div>


      <div v-if="choice5.trim() !== ''" class="item-container" @click="onChoose(action5)">
        <span class="text-overlay">{{ choice5 }}</span>
      </div>


      <div v-if="choice6.trim() !== ''" class="item-container" @click="onChoose(action6)">
        <span class="text-overlay">{{ choice6 }}</span>
      </div>
    </div>


  </div>

</template>
<script>
export default {
  mounted() {
    let duration;
    this.bridge.invoke('player', 'getDuration').then(v =>{
      duration = v * 1000;
      console.log('视频时长:',duration)
    });

    var isShow = false;
    this.bridge.on('player', 'timeupdate', time => {
      let miliSec = time * 1000 // 单位统一成毫秒
      // 由于部分设备取时间不准确 建议采用以下方式 结束前200ms判断为结束。
      if(duration > 0 && miliSec >= duration - 500) {
        if(this.visible || isShow)return
        isShow = true
        console.log('播放结束,开始显示选项')
        this.show();
      }
    });
  },
  methods: {
    onChoose(actionName) {
      // this.action则是上面表单配置的内容
      this.bridge.invoke('engine', 'action', actionName);
      this.hide();
    }
  }
};
</script>
<style>


.container {
  position: absolute;
  transition: opacity .5s ease;
  background: linear-gradient(rgba(0, 0, 0, 0),rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.8));
}


/* 网格布局 */
.option-container {
  display: flex;
  flex-wrap: wrap; /* 允许项目换行 */
  justify-content: center; /* 水平居中对齐 */
}


.item-container {
  position: relative;
  display: inline-block;
  width: 5rem;
  height: 1rem;
  line-height: 1rem;
  margin-right: 0.8rem;
  margin-bottom: 0.3rem;

  text-align:center;
  font-size: 0.4rem;
  color: #ffffff;

  background: rgba(255,255,255,0.1);
  border-radius: 4px;
  border: 1px solid #FFFFFF;

  animation: floatAni 3s ease-in-out -2.5s infinite;


  &:hover {
    border: 1px solid #fd5439;
    color: #fd5439;
    box-shadow: 0 0 0.2rem 0px #fd5439;
    /* width: 5.2rem; */
    /* height: 1.1rem; */
    /* transition: width .2s ease, height .2s ease; */
  }
}


/* 定义飘动动画的 keyframes */
@keyframes floatAni {
  from {
    transform: translatey(0px) scale(1);
  }
  50% {
    transform: translatey(-4px) scale(1.05);
  }
  to {
    transform: translatey(0px) scale(1);
  }
}


.option-border {
  width: 2rem;
  height: 1px;
  background: #00000000;

  display: block;
  text-align: center;
  position: relative;
  margin: auto;

  margin-bottom: 0.5rem;
}


.option-border-show {
  width: 2rem;
  height: 1px;
  background: #fd5439;

  display: block;
  text-align: center;
  position: relative;
  margin: auto;

  margin-bottom: 0.5rem;
}



p {
  font-size: 0.6rem;
  color: white;
  text-align: center;
  /* text-stroke: 0.01rem #000000;
  -webkit-text-stroke: 0.01rem #000000; */
  text-shadow: 0 1px black, 1px 0 black, -1px 0 black, 0 -1px black;
  margin-bottom: 0.1rem;
  margin-top: 0.5rem;
}

img {
  width: 100%;
  height: 100%;
}

</style>
